package com.gdufe.mistakebook.mapper;

import com.gdufe.mistakebook.entity.Question;
import com.gdufe.mistakebook.entity.vo.count.CreateTimeQuestionCountVO;
import com.gdufe.mistakebook.entity.vo.count.PriorityQuestionCountVO;
import com.gdufe.mistakebook.entity.vo.count.SubjectQuestionCountVO;
import com.gdufe.mistakebook.entity.vo.QueryQuestionsVo2;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @author hoshino
 * @description 针对表【question】的数据库操作Mapper
 * @createDate 2024-03-20 13:20:18
 * @Entity com.gdufe.mistakebook.entity.Question
 */
@Mapper
public interface QuestionMapper {

    /**
     * 分页条件查询
     *
     * @param questionTitle
     * @param subjectName
     * @param startTime
     * @param endTime
     * @param labelName
     * @return
     */
    Page<QueryQuestionsVo2> queryQuestions(@Param("questionTitle") String questionTitle, @Param("subjectName") String subjectName, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("labelName") String labelName);


    /**
     * 新增错题
     *
     * @param question
     * @return
     */
    int insertQuestion(Question question);


    /**
     * 随机从数据库中查出count条错题
     *
     * @param count
     * @return
     */
    @Select("select * from mistake_book.question where status = 1 order by rand() limit #{count}")
    List<Question> randomQueryQuestions(Integer count);

    /**
     * 更改错题信息
     *
     * @param question
     */
    void update(Question question);

    /**
     * 根据id获取错题信息
     *
     * @param id
     * @return
     */
    @Select("select * from mistake_book.question where id = #{id}")
    Question selectById(Integer id);

    /**
     * 统计各种学科对应的错题数量
     * @return
     */
    @Select("select subject,count(*) as count from question group by subject;")
    List<SubjectQuestionCountVO> selectSubjectQuestionCount();

    /**
     * 统计优先级对应的错题数量
     */
    @Select("select priority,count(*) as count from question group by priority;")
    List<PriorityQuestionCountVO> selectPriorityQuestionCount();

    @Select("SELECT DATE_FORMAT(create_time, '%Y-%m') AS create_time, COUNT(*) AS count FROM question GROUP BY DATE_FORMAT(create_time, '%Y-%m');")
//    @Select("select month(create_time) as create_time, count(*) as count from question group by create_time order by create_time")
    List<CreateTimeQuestionCountVO> selectCreateTimeQuestionCount();
}




